#include "GlGuiControl.h"
#include "GlGuiEventRecognizer.h"
#include <Windows.h>
#include <gl/glut.h>



GlGuiControl::GlGuiControl (int argc, char ** argv, uint customMode)
  : GlControl (argc, argv), _mainWidget (NULL)
{
  _setupUI ();
  createWindow (customMode | GLUT_DOUBLE | GLUT_RGB,
    _mainWidget->getTitle ().c_str (), false,
    _mainWidget->getStyle ().getWidth (),
    _mainWidget->getStyle ().getHeight ());
}



GlGuiControl::~GlGuiControl ()
{
  if (_mainWidget != NULL)
    delete _mainWidget;
}



void GlGuiControl::registerMainWidget (GlWidget * widget) 
{
    _mainWidget = widget;
}



void GlGuiControl::drawEvent ()
{
  _mainWidget->draw ();
}



void GlGuiControl::keyPressEvent (GlEvent e)
{
  throw std::exception("The method or operation is not implemented.");
}



void GlGuiControl::mouseEvent (GlEvent e)
{
  GlGuiEventRecognizer::getSingleton ().newEventRaised (e);
  GlGuiEvent guiEvent (&e);
  _mainWidget->registerActionsTo (guiEvent);
  guiEvent.doActions ();
}



void GlGuiControl::timerEvent ()
{
  throw std::exception("The method or operation is not implemented.");
}



void GlGuiControl::mainLoop ()
{
  throw std::exception("The method or operation is not implemented.");
}



void GlGuiControl::reshapeWindowEvent (int width, int height)
{
  throw std::exception("The method or operation is not implemented.");
}
